package com.lemonfish.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lemonfish.mapper.OrderlistMapper;
import com.lemonfish.pojo.dto.UserDTOLikeSearch;
import com.lemonfish.pojo.entity.Orderlist;
import com.lemonfish.service.OrderlistService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * 订单相关Service实现
 *
 * @author Lemonfish
 * @version 1.0
 * @date 2020-03-14
 * Copyright © Chao Zhang
 */
@Service
@Slf4j
public class OrderlistServiceImpl extends BaseCustomServiceImpl<OrderlistMapper, Orderlist> implements OrderlistService {
    @Autowired
    OrderlistMapper orderlistMapper;

    @Override
    public IPage<Orderlist> getAllByLike(UserDTOLikeSearch content, long curPage, long pageSize, String order, String column) {
        QueryWrapper<Orderlist> queryWra = new QueryWrapper();
        System.out.println(content);
        if (!StringUtils.isEmpty(content.getName())) {
            queryWra.like("name", content.getName());
        }
        if (!StringUtils.isEmpty(content.getEmail())) {
            queryWra.like("email", content.getEmail());

        }

        if ("descending".equals(order)) {
            queryWra.orderByDesc(column);
        } else {
            queryWra.orderByAsc(column);
        }

        return orderlistMapper.selectPage(new Page<>(curPage, pageSize), queryWra);
    }

    @Override
    public IPage<Orderlist> getOrderList(long curPage, long size, String order, String column) {
        QueryWrapper<Orderlist> queryWra = new QueryWrapper<>();

        if ("descending".equals(order)) {
            queryWra.orderByDesc(column);
        } else {
            queryWra.orderByAsc(column);
        }

        return orderlistMapper.selectPage(new Page<>(curPage, size), queryWra);
    }
}
